package me.moscrop.RootCommand.commands;

import me.moscrop.RootCommand.utilities.Chat;
import me.moscrop.RootCommand.utilities.Utility;

import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Creature;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;

public class KillMob {

	public static boolean killmob(CommandSender sender, Command command, String label, String[] args) {
		if (!(sender instanceof Player)) {
			sender.sendMessage(" Command must be run in game.");
			return true;
		}
		
		if (args.length < 1) return false;
		
		int mobsKilled = 0;
		int radius = Integer.parseInt(args[0]);
		Player player = (Player) sender;
		Location location = player.getLocation();
		
		for(Entity entity : Utility.getNearbyMobs(location, radius)){
			mobsKilled++;
			if(entity instanceof Creature){
				((Creature) entity).damage(((Creature) entity).getHealth());
			}
		}
		
		Chat.message(player, "killed  "+ mobsKilled + " mobs");
		return true;
	}
}
